﻿using Coldairarrow.Business.Backstage.Valickets;
using Coldairarrow.Entity.Backstage.Valickets;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Backstage.Valickets
{
    [Route("/Backstage/Valickets/[controller]/[action]")]
    public class BS_VailTicketController : BaseApiController
    {
        #region DI

        public BS_VailTicketController(IBS_VailTicketBusiness bS_VailTicketBus)
        {
            _bS_VailTicketBus = bS_VailTicketBus;
        }

        IBS_VailTicketBusiness _bS_VailTicketBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<BS_VailTicket>> GetDataList(PageInput<SearchDTO> input)
        {
            return await _bS_VailTicketBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<BS_VailTicket> GetTheData(IdInputDTO input)
        {
            return await _bS_VailTicketBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 后台——更改优惠券状态
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task ChangeTicketState(IdInputDTO input)
        {
             await _bS_VailTicketBus.ChangeState(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(BS_VailTicket data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);
                data.State = true;
                await _bS_VailTicketBus.AddDataAsync(data);
            }
            else
            {
                await _bS_VailTicketBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _bS_VailTicketBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}